Repository navigation
fix(#986): order MCP tool sets by turn so a late drop or check never overwrites a newer one - #1004
Conversation
…overwrites a newer one Each turn draws a place as its check starts; a fixed set keeps the turn that fixed it. A late check, a stopped turn's forget, or a timed-out hold's drop writes only if no later turn has fixed the thread's set. The drop stands for the hold's latest turn, so that turn's own late check still replaces it. Claude: a plan that matches the process's opened key refreshes it, so the 4096 cap drops the thread used longest ago, and the opened keys get a test reset hook with a test of their own for the "never wider" comparison. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
lens: code · reviewer: lens agent (Opus 5.5) · read at: 980f15a Points checked with no finding:
verdict: safe to merge 🤖 Generated with Claude Code |
|
lens: state · reviewer: lens agent (Opus 5.5, independent of the other lens) · read at: 980f15a 🤖 Generated with Claude Code |
…ap, latched Codex tests - fixT3ToolSet and holdT3ToolSet take the turn as a required argument: a caller can no longer draw its number at write time and rank a stale read newest. - Remember the latest turn dropped at the 4096 cap and use it for a thread with no entry, so an older turn's late check cannot replace a newer, narrower set after the drop. - Test the joiner bump in holdT3ToolSet: a joined turn still checking as the bound passes keeps the first turn's late (wide) check from writing. - The Codex #986 tests await the hold's done (released after each check's fix) instead of a real 20 ms wait. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
not a lens: narrow check after fix round 1 Verdict: SAFE TO MERGE (head 1. Fix 3 (
2. Red without the change (undone and run here)
3. Fix 2: every production caller passes a turn drawn before its profile read
4. Fix 5: Codex tests
5. Dropped item 4 (
Runs here (one at a time, from a fresh install):
All scratch edits were reverted and the temp worktree removed. fork-ci-result: pass on 🤖 Generated with Claude Code |
Fixes #986
One fix covers the three race points, as the issue suggested. Each turn draws a place (
nextT3ToolSetTurn) as its check starts, before it reads the profile. Every fixed set keeps the turn that fixed it. A late check, a stopped turn'sforget, or a timed-out hold's drop writes only if no later turn has fixed the thread's set. A hold remembers the latest turn that took or joined it. Its drop writes Refused for that turn, so that turn's own late check still replaces the refusal, but an older turn's check does not.Callers that fix sets now pass their turn: the Codex
turn/startcheck, the Codexturn/startedwatch (the hold and the profile step share one turn), the turn check before a provider call (mcpProfileTurnCheck.ts), and the Claude plan (its refusals, the same-key fix, and the fix when the options are read).mcpT3ToolSets.tsdrop overwrites a newer turn's set: a joining turn fixed its set while the first turn's check is stuckcodexMcpProfile.test.ts"a joining turn fixed its set while the first is stuck: the drop keeps it" (red:expected true to be false, the drop wrote Refused)codexMcpProfile.test.ts"a turn T3 starts itself while a Codex turn's hold is stuck: the drop keeps its set" (red: same)codexMcpProfile.tstwo checks finish out of order; the last one to finish wins, so a late check can widen the setprofileStepfixes with the turn drawn before the read; an older turn's late fix is ignoredcodexMcpProfile.test.ts"two checks finishing out of order: the later turn's set stands" (red:expected 'Groups' to deeply equal ['waits'], widened back to all);mcpProfileTurnCheck.test.ts"two turns' checks finishing out of order" (red: same, on the pre-call check)mcpT3ToolFilter.test.ts"a check fixed its set but has not released yet as the bound passes: its set stands" (red: the request gotfalse/Refused); "the hold's own turn fixes its set as the bound passes" (same turn exactly)claudeMcpProfile.tsthe "never wider" plan-key check has no test of its own__testing.clearOpenedPlanKeys(pluskeepOpenedPlanKey,hasOpenedPlanKey); the two tests that relied on keys left by earlier tests now start emptyclaudeMcpProfile.test.ts"never wider: a process opened with one plan meets a different, wider one". The code was already right, so the red is a mutation check: with the comparison cut down toopenedPlanKeys.has(...), this test fails (expected ['threads','orchestration'] to equal 'Refused') and the 55 tests that were already there all passclaudeMcpProfile.tsthe 4096 cap drops the process opened first, not the one used longest agoclaudeMcpProfile.test.ts"the cap drops the thread whose process was used longest ago" (red:expected false to be true, the thread in use was dropped)State questions, with tests:
mcpProfileTurnCheck.test.ts"stopped half-way after a later turn fixed its set", red:expected undefined). A turn's own stop still clears its set. After that stop, an older turn's late check still writes nothing, and a request's remembered set or a later turn still writes (mcpT3ToolFilter.test.tsunit tests). A check interrupted mid-way still releases its hold (existing test).The new unit tests for the turn API (
nextT3ToolSetTurn,forgetT3ToolSet(id, turn)) are red on main withnextT3ToolSetTurn is not a function, since the API is new. Every other red above is a behavioral assertion failure.Checks run (first push): the 4 changed test files one at a time (
mcpProfileTurnCheck30,mcpT3ToolFilter25,codexMcpProfile53,claudeMcpProfile57, all passed), plusfmt:check,lint(0 errors), and theapps/servertypecheck.Left
Round 1
Both lenses said safe to merge. Minors handled per the round rule (fixed here when small and in scope, else dropped with a reason). Merged
origin/mainfirst.held.turn = Math.max(held.turn, turn)inholdT3ToolSethas no testmcpT3ToolFilter.test.ts"a joined turn still checking as the bound passes: the first's late check cannot widen" (turn A holds, turn B joins, B still checking at the bound, A's late wide check writes nothing, B's replaces the refusal). Red with the line removed:expected 'Groups' to be 'Refused'(A's wide set written)fixT3ToolSetandholdT3ToolSetdefaultturntonextT3ToolSetTurn()turnis now required on both. Every production caller already passed the turn drawn before its profile read; tests now draw it themselvesmcpT3ToolSets.tsremembers the latest turn dropped at the cap (droppedTurn) and uses it, not 0, for a thread with no entry (innewest,rememberT3ToolSetand the hold drop). A too-old check then writes nothing and the next request works the set out from the settingsmcpT3ToolFilter.test.ts"keeps at most MAX_T3_TOOL_SETS threads, dropping the oldest" (extended: older late check after the drop writes nothing, nor over a request's set; a later turn writes). Red without the remembered turn:expected { name: 'older' } to be undefined__testinghooks such askeepOpenedPlanKeyimportable by production codeno-restricted-importscannot seeX.__testingthrough a namespace import (the repo's convention), and a new oxlint rule would mean changing the shared lint plugin andvite.config.ts, which is outside this PR. No non-test file uses another module's__testingtoday (grep)settle)settle. A gated check's end is awaited via the hold'sdone, which completes when every check holding it releases, after its fix. Checks whose profile read is not gated run insideemit(forked withstartImmediately), so there is nothing to wait fornewestforced to true, so the latch does wait for the late checkState questions for the round-1 code:
forgetT3ToolSetand the drop use the same "latest fixed turn" check, now aware of the cap.droppedTurnis 0 with everything else, so any check writes, as before.__testing.clearresets it too.droppedTurn. That is one number for all threads, so a brand-new thread's check drawn before a later drop also writes nothing. Its requests then work the set out from the current settings (never wider than they allow), and its next turn writes as usual.Round-1 checks: the 4 changed test files one at a time.
codexMcpProfile53,mcpProfileTurnCheck30,claudeMcpProfile57: all passed.mcpT3ToolFilter: 15 passed (every in-memory test, including the new and extended ones); its 11 socket tests could not run on the machine used (connections to 127.0.0.1 are blocked there,ConnectTimeoutError), so CI runs them.vp run check:changed: format, lint (after trimming one comment), knip, graphql and typecheck pass; its test step fails only on those same 11 socket tests.General vs project
mcpT3ToolSets.ts(fix, forget, remember, drop) carries the turn it is for. New callers draw it withnextT3ToolSetTurn()before they read the profile.🤖 Generated with Claude Code